//
//  CXBtPeriModel.h
//  JwPack
//
//  Created by 陈警卫 on 2025/8/12.
//

#import <Foundation/Foundation.h>
#import <CoreBluetooth/CoreBluetooth.h>

// 外设状态
typedef NS_ENUM(NSUInteger , CXBtPeriState) {
    CXBtPeriStateInit = 0,       // 默认
    CXBtPeriStateScaned,         // 扫描成功
    CXBtPeriStateConnecting,     // 正在连接(持有)
    CXBtPeriStateConnected,      // 连接成功
    CXBtPeriStateConnectFail,    // 连接失败
    CXBtPeriStateNotifyed,       // 订阅成功
    CXBtPeriStateDisconnected,   // 设备断开
};


@interface CXBtScanModel : NSObject

// - 扫描连接

/// 将要连接的外设uuid
@property (nonatomic, strong) NSString *connectUuid;
/// 将要连接的外设name
@property (nonatomic, strong) NSString *connectName;

// - 连接参数

/// 通讯服务UUID数组
@property (nonatomic, strong) NSMutableSet<CBUUID *> *serviceUUIDs;
/// 写入特征UUID数组
@property (nonatomic, strong) NSMutableSet<CBUUID *> *writeUUIDs;
/// 订阅特征UUID数组
@property (nonatomic, strong) NSMutableSet<CBUUID *> *notifUUIDs;

@end


@interface CXBtPeriModel : NSObject

// - 状态

@property (nonatomic, assign) CXBtPeriState state;

// - 连接订阅

/// 扫描连接参数
@property (nonatomic, strong) CXBtScanModel *scanModel;

/// 外设
@property (nonatomic, strong) CBPeripheral *peri;
/// 写入特征
@property (nonatomic, strong) CBCharacteristic *writeChara;
/// 订阅特征
@property (nonatomic, strong) CBCharacteristic *notifChara;
/// 广播数据
@property (nonatomic, strong) NSDictionary *advDict;
/// 扫描信号
@property (nonatomic, strong) NSNumber *rssi;

/// 外设uuid
- (NSString *)periUuid;

/// 外设name
- (NSString *)periName;

/// 外设制造商数据
- (NSData *)periMaferData;

// - 配置

/// 是否通过恢复设备连接(默认NO)
@property (nonatomic, assign) BOOL isRetrieve;

/// 是否被动断开自动复连(默认NO)
/// 需要在连接成功步骤后面的回调中设置
/// didConncetedPeri
/// didNotifedPeri
@property (nonatomic, assign) BOOL isAutoReconnect;

/// 连接超时时间(默认0 不设置超时)
@property (nonatomic, assign) CGFloat timeout;

/// 计时器
@property (nonatomic, strong) NSTimer *timer;

/// 开始计时
- (void)startTimer;

/// 结束计时
- (void)endTimer;

/// 回调超时
/// error.code 1:连接超时
@property (nonatomic, copy) void(^didTimeoutAction)(NSError *error);


@end

